<@pp.dropOutputFile/>
<#-- iterate table list-->
<#list doc.tables as table>

<#-- generate package name -->
<#assign package = doc.groupid?replace(".", "/")> 
<#assign package = package + "/" + doc.artifactid?replace(".", "/")>
<#assign package = package + "/" + table.moduleid?replace(".", "/")>
<#assign fileName = table.name?cap_first>
<@pp.changeOutputFile name="/main/" + package + "/dao/" + fileName + "Mapper.java"/>
/*
 * File name : ${fileName}.java ${doc.date}
 * Copyright ${doc.copyright}. All rights reserved.
 */
package ${package?replace("/", ".")}.dao;

import java.util.List;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.session.RowBounds;
import org.springframework.transaction.annotation.Transactional;
import ${package?replace("/", ".")}.domain.${fileName};

/**
 * Interface ${fileName}Mapper
 * ${fileName} mapper.
 * @author ${doc.author}
 * @version ${doc.version}, ${doc.date}
 */
public interface ${fileName}Mapper {
	
	/**
	 * Insert new ${fileName} object.
	 * @param newValue New object.
	 * @return The number of rows affected.
	 */
	@Insert("insert into ${fileName}(<#list table.fields as field>${field.name}<#if field_has_next>,</#if></#list>) values(<#list table.fields as field><#noparse>#{</#noparse>${field.name}<#noparse>}</#noparse><#if field_has_next>,</#if></#list>)")
	<#if doc.database?lower_case != "oracle">
	@Options(useGeneratedKeys=true, keyProperty="id")
	<#else>
	@Options(useGeneratedKeys=true, keyProperty="id")
	/*
	@SelectKey(statement="SELECT ${fileName?upper_case}_ID_SEQ.NEXTVAL FROM DUAL", 
	keyProperty="id", resultType=int.class, before=true)
	*/
	</#if>
	public int insert(${fileName} newValue);
	
	/**
	 * Delete object by id.
	 * @param id Target id.
	 * @return The number of rows affected.
	 */
	@Delete("delete from ${fileName} where ID = <#noparse>#{id}</#noparse>")
	public int deleteById(@Param("id")int id);

	/**
	 * Delete all objects.
	 * @return The number of rows affected.
	 */
	@Delete("delete from ${fileName}")
	public int deleteAll();

	/**
	 * Delete objects which id were included in items array.
	 * @param items Target ids.
	 * @return The number of rows affected.
	 */
	public int deleteItems(@Param("items")Integer[] items);

	/**
	 * Retrieve object by id.
	 * @param id Target ids.
	 * @return Target object.
	 */
	@Select("select * from ${fileName} where ID = <#noparse>#{id}</#noparse>")
	@Results(value={ 
		<#list table.fields as field>
		@Result(property="${field.name}", column="${field.name?upper_case}")<#if field_has_next>,</#if>
		</#list>
	})
	public ${fileName} findById(@Param("id")int id);
	
	/**
	 * Retrieve all objects.
	 * @return Target objects.
	 */
	@Select("select * from ${fileName}")
	@Results(value={ 
		<#list table.fields as field>
		@Result(property="${field.name}", column="${field.name?upper_case}")<#if field_has_next>,</#if>
		</#list>
		})
	public List<${fileName}> findAll();
	
	/**
	 * Retrieve objects in specified page.
	 * @param rowBounds Page information.
	 * @return Target objects.
	 */
	@Select("select * from ${fileName}")
	@Results(value={ 
		<#list table.fields as field>
		@Result(property="${field.name}", column="${field.name?upper_case}")<#if field_has_next>,</#if>
		</#list>
		})
	public List<${fileName}> findPage(@Param("rowBounds")RowBounds rowBounds);
	
	/**
	 * Update specified object.
	 * @param newValue Target object.
	 * @return The number of rows affected.
	 */
	@Update("update ${fileName} set <#list table.fields as field><#if field.name!="id">${field.name}=<#noparse>#{</#noparse>${field.name}<#noparse>}</#noparse><#if field_has_next>,</#if></#if></#list> where id = <#noparse>#{id}</#noparse>")
	public int update(${fileName} newValue);

	/**
	 * Retrieve the number of objects.
	 * @return The number of objects.
	 */
	@Select("select count(*) from ${fileName}")
	public int size();
}
</#list>